import { shareList,shareKnowledge,inquireShare,deleteShare } from '@/services/knowledgemanagement';

export default {
  namespace:'knowledgeBaseSharing',

  state: {
  
  },
  effects: {
    *fetch({ payload, callback }, { call, put }) {  // 知识库总揽 分类树
      const response = yield call(shareList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchb({ payload, callback }, { call, put }) { // 知识库总揽 删除分类
      const response = yield call(shareKnowledge, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchc({ payload, callback }, { call, put }) {  // 知识库总揽 停用/启用分类
      const response = yield call(inquireShare, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchd({ payload, callback }, { call, put }) {  // 知识库总揽 修改分类名称
      const response = yield call(deleteShare, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    }
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
       
      };
    },
  },
};
